<template>
  <el-dialog
    v-model="visible"
    :close-on-click-modal="false"
    title="订单详情"
    @close="formRef.resetFields()"
    draggable
  >
    <el-form
      :model="formParams"
      ref="formRef"
      :inline="true"
      label-position="left"
      label-width="auto"
    >
      <el-form-item label="手机号" prop="mobile">
        <el-input
          v-model.trim="formParams.mobile"
          placeholder="请输入"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房间号/工位号" prop="remark">
        <el-input
          v-model.trim="formParams.remark"
          placeholder="请输入"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="&nbsp;">
        <el-button @click="handleReset()">重置</el-button>
        <el-button type="primary" @click="handleQuery()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="list">
      <el-table-column label="手机号" align="center" prop="mobile" />
      <el-table-column label="餐食名称" align="center" prop="comboName" />
      <el-table-column label="份数" align="center" prop="comboNum" />
      <el-table-column label="餐食价格" align="center" prop="comboPrice" />
      <el-table-column label="房间号/工位号" align="center" prop="remark" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="formParams.pageNum"
      v-model:limit="formParams.pageSize"
      @pagination="getList()"
    />
  </el-dialog>
</template>
<script setup>
import { getEnterpriseOrderDetailsListApi } from '@/api/order'

const list = ref([])
const visible = ref(false)
const total = ref(0)
const formParams = ref({
  mobile: null,
  remark: null,
  enterpriseOrderSn: null,
  pageNum: 1,
  pageSize: 10
})
const loading = ref(false)
const formRef = ref()
function init(enterpriseOrderSn) {
  visible.value = true
  formParams.value.enterpriseOrderSn = enterpriseOrderSn
  handleQuery()
}
function handleQuery() {
  formParams.value.pageNum = 1
  getList()
}
function getList() {
  loading.value = true
  getEnterpriseOrderDetailsListApi(formParams.value)
    .then((res) => {
      console.log(res)
      total.value = res.data.total
      list.value = res.data.rows
    })
    .finally(() => {
      loading.value = false
    })
}
function handleReset() {
  formRef.value.resetFields()
  getList()
}

defineExpose({
  init
})
</script>
<style lang="scss" scoped>
.el-input {
  width: 215px;
}
</style>
